/*
 * @(#)EmailReceiverImpl.java
 *
 * Copyright (c) 2005 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */

package com.dcivision.mail.core;

import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;
import com.dcivision.framework.Utility;

/**
 * EmailReceiverFactory.java
 *
 * Factory class for getting the correct email implementation 
 * base on user mail setting
 *
 * @author        Ryan Kwan
 * @company     	DCIVision Limited
 * @creation date 20/06/2005
 * @version     $Revision: 1.5.2.1 $
 */

public class EmailReceiverFactory{

  public static final String REVISION = "$Revision: 1.5.2.1 $";

  public final static int MAIL_LOTUS_DOMINO = 0;
  public final static int MAIL_STANDARD_MAIL = 1;

  /**
   * Base on the user mail setting to retrive the correct implemenation
   * @param	sessionContainer	session continer for getter user id
   * @return 	the EmailReceiver implementation base on the user email settings
   */
  public static EmailReceiver getEmailReceiverInstance(SessionContainer sessionContainer) {       
    if (Utility.isEmpty(SystemParameterFactory.getSystemParameter(SystemParameterConstant.DOMINO_HOST))) {
      //pop3 or imap returns standard implementaion
      return EmailReceiverImpl.newInstance(sessionContainer);
    } else {
      //Domino mail returns DominoEmailReceiverImpl
      return LotusDominoReceiverImpl.newInstance(sessionContainer);
    }
  }
  
  /**
   * Base on the input mail server type to retrive the correct implemenation
   * @param	sessionContainer	session continer for getter user id
   * @return 	the EmailReceiver implementation base on the user email settings
   */
  public static EmailReceiver getEmailReceiverInstanceByServerType(SessionContainer sessionContainer,String serverType) {       	  
    if (EmailReceiver.RECEIVE_EMAIL_SERVER_TYPE_DOMINO.equals(serverType)){
      //Domino mail returns DominoEmailReceiverImpl
      return LotusDominoReceiverImpl.newInstance(sessionContainer);      
    }else if(EmailReceiver.RECEIVE_EMAIL_SERVER_TYPE_DOMINO_JOURNALING.equals(serverType)){      
      return LotusDominoReceiverImpl.newInstance(sessionContainer);
    }else{
      //pop3 or imap returns standard implementaion
      return EmailReceiverImpl.newInstance(sessionContainer);
    }
  }  
}

